
package com.hospital.phyexam.controller;

import com.alibaba.fastjson.JSONObject;
import com.hospital.phyexam.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/project")
public class ProjectController {

    @Autowired
    ProjectService projectService;


/**
     * 获取体检项目列表json数据
     */

    @RequestMapping(value = "/all", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    @ResponseBody
    public String getProjects() {
        return projectService.getAllProject();
    }

    @RequestMapping(value = "/proName", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String getProjectsByName(@RequestBody String string) {
        String name=JSONObject.parseObject(string).getString("proName");
        return projectService.selectByProName(name);
    }

    @RequestMapping(value = "/add", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String add(@RequestBody String string) {
        Integer ofcId=Integer.parseInt(JSONObject.parseObject(string).getString("ofcId"));
        String proName=JSONObject.parseObject(string).getString("proName");
        String proNorm=JSONObject.parseObject(string).getString("proNorm");
        return projectService.addPro(ofcId,proName,proNorm);
    }

  @RequestMapping(value = "/update", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String update(@RequestBody String string) {
        Integer id=Integer.parseInt(JSONObject.parseObject(string).getString("id"));
      String proName=JSONObject.parseObject(string).getString("proName");
      String proNorm=JSONObject.parseObject(string).getString("proNorm");
        return projectService.update(id,proName,proNorm);
    }
    @RequestMapping(value = "/delete", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String delete(@RequestBody String string) {
        Integer id=Integer.parseInt(JSONObject.parseObject(string).getString("id"));
        return projectService.delete(id);
    }
}

